{
  "properties" : { },
  "id" : "c4bb5aa092a9423da5fa80b7c098349f",
  "script" : null,
  "groupId" : "1662294e27c44d22ad9cca536617efe7",
  "name" : "下发",
  "createTime" : 1727071182561,
  "updateTime" : 1726651714398,
  "lock" : "0",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "sendCmdToDeviceList",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"hostList\": [\r\n        \"4.61.0.3\"\r\n    ],\r\n    \"templateId\": \"1816005220194414594\",\r\n    \"cmdRequestList\": [\r\n        \"dis  version\",\r\n        \"dis ip int b\"\r\n    ]\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": \"正在下发，稍后查看下发记录\"\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "root",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "hostList",
      "value" : "",
      "description" : "",
      "required" : true,
      "dataType" : "Array",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "",
        "value" : "4.61.0.3",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    }, {
      "name" : "templateId",
      "value" : "1788510280971251713",
      "description" : "",
      "required" : true,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "cmdRequestList",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Array",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "",
        "value" : "dis  cu",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "正在下发，稍后查看下发记录",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
// import com.kd.ndmp.biz.device.model.SshCmdInfo;
// import com.kd.ndmp.util.biz.NetDeviceBizUtil
// import com.kd.ndmp.biz.device.service.impl.SshCmdExecServiceImpl;
import java.lang.StringBuilder;
import com.kd.ndmp.util.KafkaUtil
import log;
import com.kd.ndmp.util.IdUtil;


 


var ipMapRegion = db.table("ndmp_device").
column("ip").
column("net_region").
column("id").
where().in("ip", body.hostList).select()

//根据id 获取厂商 数字
var getFirmById = (deviceId) => {

  return   db.selectOne("""
    
        SELECT
            device_firm
        FROM
            ndmp_net_device_model_info
        WHERE
                ID IN ( SELECT device_model_id FROM ndmp_device WHERE ID = #{deviceId})
    """)
 
}
// 根据id  获取设备账号密码
var getDevAccount = (deviceId) => {

    let devPro = db.selectOne("""
                                    SELECT
                                        DEVICE_USERNAME username ,
                                        DEVICE_PORT port,
                                        DEVICE_PASSWORD password
                                    FROM
                                        NDMP_NET_DEVICE_PROTOCOL nndp
                                    WHERE
                                        DEVICE_ID = #{deviceId}
                         """)

    if (is_null(devPro.port)) {
        devPro.port = 22
    }
    return devPro
}

// 生成初始命令
var getCmd = (cmdListInit, intFirm) => {
    var firstCmd
    if (1 == infFirm) {
        firstCmd = "screen-length 0 temporary \r\n"; //华为
    } else if (2 == intFirm) {
        firstCmd = "screen-length disable  \r\n"; //h3c
    } else {
        firstCmd = "terminal length 0 \r\n"; //中兴、锐捷
    }
    cmdListInit.add(0,firstCmd)

    return cmdListInit;

}


for (ipRegion in ipMapRegion) {
    let sshCmdInfo = {}
    // 模版ID
    sshCmdInfo.templateId = body.templateId;
    //设备ip
    sshCmdInfo.host = ipRegion.ip;
    
    //设备id
    sshCmdInfo.deviceId = ipRegion.id;

        
    //id
    sshCmdInfo.id = IdUtil.getSnowflakeNextId();

    //要知道下发给哪一个代理
    sshCmdInfo.region = ipRegion.netRegion;
    // 命令
    let intFrimTemp = getFirmById(sshCmdInfo.deviceId)
    let finishCmd = getCmd(body.cmdRequestList, intFrimTemp.deviceFirm)
    sshCmdInfo.cmdRequestList = finishCmd;
 




    //设备账号信息
    let devAccount = getDevAccount(ipRegion.id)
    sshCmdInfo.username = devAccount.username;
    sshCmdInfo.port = devAccount.port;
    sshCmdInfo.password = devAccount.password;
 

    KafkaUtil.sendMsg(sshCmdInfo, "topic_exec_batch_cmd")

}



return "正在下发，稍后查看下发记录"